﻿using System;

namespace MainApplication.BaseLerning
{
    public class LINQDemo
    {
        public static String test()
        {
            String output_str = "查询结果：\n";
            {
            //    // Specify the data source.
            //    int[] scores = [97, 92, 81, 60];

            //    // Define the query expression.
            //    IEnumerable<int> scoreQuery =
            //        from score in scores
            //        where score > 80
            //        select score;


            //    // Execute the query.
            //    foreach (var i in scoreQuery)
            //    {
            //        output_str += " " + i;
            //    }
            }

            {           
                // 1.配置数据源：
                int[] numbers = [0, 1, 2, 3, 4, 5, 6];

                // 2. 创建查询
                // numQuery is an IEnumerable<int>
                //var numQuery = 
                //     from num in numbers
                //     where (num % 2) == 0
                //     select num;

                var numQuery = numbers.Where(num=>num%2==0).Select(num=>num);   
              


                //string[] groupingQuery = ["carrots", "cabbage", "broccoli", "beans", "barley"];
                //IEnumerable<IGrouping<char, string>> queryFoodGroups =
                //    from item in groupingQuery
                //    group item by item[0];

                // 3. 执行查询并处理查询结果：
                foreach (int num in numQuery)
                {
                   output_str+=" "+ num;
                }
            }
            return output_str;
          
        }
    }
}
